'use strict';

define([
    'angular',
    'ngRoute',
    'login',
    'register',
    'tasks',
    'services/getApiServices',
], function(angular, ngRoute) {
    // Declare app level module which depends on views, and components
    return angular.module('myApp', [
            'ngRoute',
            'myApp.login',
            'myApp.register',
            'myApp.tasks',
        ])
        .config(['$routeProvider', function($routeProvider) {
            $routeProvider.otherwise({ redirectTo: '/login' });
        }])
        .controller('mainCtrl', [
            '$scope',
            '$location',
            'ApiIterface',
            function($scope, $location, ApiIterface) {
                $scope.totalCount = 0;
                $scope.completeCount = 0;
                $scope.ncompleteCount = 0;
                // ApiIterface.
                $scope.querystr = '';
                $scope.$location = $location;
                $scope.$watch('$location.path()', (now, old) => {
                    $scope.querystr = now;
                    // switch (now) {
                    //     case '/tasks/no':
                    //         $scope.querystr = '';
                    //         break;
                    //     case '/tasks/yes':
                    //         $scope.querystr.complete = true;
                    //         break;
                    //     default:
                    //         break;
                });
                ApiIterface
                    .getTaskList()
                    .then(rev => {
                        let tempdata = rev.data.data;
                        $scope.totalCount = tempdata.length;;
                        $scope.completeCount = tempdata.filter(t => t.complete == true).length;
                        $scope.ncompleteCount = tempdata.filter(t => t.complete == false).length;
                    })
                    .catch(err => console.log(err));
            }
        ])
});